<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/CoverageReport">
		<html>
			<head>
				<title><xsl:value-of select="Title"/></title>
				<style>
				A { text-decoration: none; }
body {margin:20px 20px 20px 20px;}
#border { border:1px solid #000000; }
#content {
	postion:relative;
	width:90%;
	margin-top:5%;
	margin-right:5%;
	margin-bottom:5%;
	margin-left: 5%;
	margin-bottom:5%;	
}

#section {
	margin-bottom:20px;
	border-top: solid medium navy }
				</style>
			</head>
			<body>
				<div id="border">
					<div id="content">
						<div id="section">
							<h3><xsl:value-of select="Title"/>: <xsl:call-template name="percentage"/> <xsl:if test="History">(was: <xsl:call-template name="old-percentage"/>)</xsl:if></h3>
							<p><xsl:value-of select="HitCoveragePoints"/> out of <xsl:value-of select="TotalCoveragePoints"/> coverage points hit.</p>
							<p>Was previously <xsl:value-of select="PreviousHits"/> out of <xsl:value-of select="PreviousTotal"/> coverage points hit.</p>
						</div>
						
						<div id="section">
							<h3>Namespace Test Coverage:</h3>
							<ul>
								<xsl:apply-templates 
									select="FlattenedNamespaces/*" 
									mode="summary"/>
							</ul>
						</div>

						<xsl:if test="History">			
							<div id="section">
								<h3>Movers and shakers</h3>
								<ul>
									<xsl:for-each select="FlattenedNamespaces//CoverageFile">
										<xsl:if test="not(PreviousHits=HitCoveragePoints) or not (PreviousTotal=TotalCoveragePoints)">
											<li>
												
												<a href="{concat(RelativePath, concat('/', Filename))}"> <xsl:value-of select="Filename" /> </a>
												- 
												<xsl:call-template name="difference"/>
												
												<xsl:if test="string-length(MissedLineNumbers) > 0">
													(Coverage misses at line#s <xsl:value-of select="MissedLineNumbers"/>)
												</xsl:if>		
											</li>										
										</xsl:if>				
									</xsl:for-each>
								</ul>
							</div>
						</xsl:if>
						
						<div id="section">
							<h3>File Test Coverage:</h3>
							<ul>
								<xsl:apply-templates select="FlattenedNamespaces/*"/>
							</ul>
						</div>	
						
						<xsl:if test="History">			
							<div style="background-color:#E0E0E0; position:absolute; top:100; left:600; height:100; width:{2 * count(History/Events/Event)}; border=thin;">
								<xsl:for-each select="History/Events/Event">
									<xsl:sort select="position()" data-type="number" order="descending" />
									<xsl:variable name="green" select="round(CoveragePercentage * 255)" />
									<xsl:variable name="red" select="255 - round(CoveragePercentage * 255)" />
									<xsl:variable name="color">#<xsl:call-template name="color"><xsl:with-param name="baseten" select="$red"/></xsl:call-template><xsl:call-template name="color"><xsl:with-param name="baseten" select="$green"/></xsl:call-template>00</xsl:variable>
								
									<div style="background-color:{$color}; position:absolute; top:{100 - round(CoveragePercentage*100)}; left:{position() * 2}; height:{round(CoveragePercentage*100)}; width:2;"> </div>
								</xsl:for-each>
								time &gt;
							</div>
						</xsl:if>		
					</div>
					
					<div id="section">
						Report generated on <xsl:value-of select="GeneratedDate"/> by <a href="http://www.sourceforge.net/projects/ncover">NCover</a> version <xsl:value-of select="Version"/>
						<p>
						Disclaimer: 100% Test coverage is no guarantee of the quality of the tests.
						</p>
					</div>
				</div>
			</body>
		</html>
	</xsl:template>

	<xsl:template name="difference">
		<!-- was good or bad? or more tests needed -->
		<xsl:choose>
			<xsl:when test="HitCoveragePoints &gt; PreviousHits">
				<!-- more tests = good thing! -->
				more tests written ;-)
			</xsl:when>
			<xsl:when test="TotalCoveragePoints &lt; PreviousTotal">
				<!-- less coverage points = simpler implementation = good thing -->
				code simplified ;-)
			</xsl:when>
			<xsl:when test="(TotalCoveragePoints &gt; PreviousTotal) and (PreviousHits = PreviousTotal)">
				<!-- more implementation done, yet tests required! = amber thing -->
				write more tests for this! :-~
			</xsl:when>
			<xsl:when test="(TotalCoveragePoints = PreviousTotal) and (HitCoveragePoints &lt; PreviousHits)">
				your going the wrong way! :-(
				<!-- same implementation, less tests! = bad thing -->
			</xsl:when>
			<xsl:otherwise>
				:-(
				<!-- assume everything else as a bad thing -->
			</xsl:otherwise>
		</xsl:choose>
	
		<xsl:call-template name="old-percentage" /> --> <xsl:call-template name="percentage" />.
	</xsl:template>						
													
	<xsl:template match="CoverageNamespace" mode="summary">
		<li>
			<a href="#{generate-id(Namespace)}"> namespace <xsl:value-of select="Namespace"/> { <xsl:call-template name="percentage"/> }</a>
		</li>
	</xsl:template>
	
	<xsl:template match="CoverageNamespace">
		<div style="background-color: #E5E5E5;">
			<li style="list-style-type:none">
				<xsl:call-template name="percentage"/>
				<a name="{generate-id(Namespace)}"> namespace <xsl:value-of select="Namespace"/> {</a>
				
				<xsl:if test="not(PreviousHits=HitCoveragePoints) or not (PreviousTotal=TotalCoveragePoints)">
					(Was <xsl:value-of select="PreviousHits"/>/<xsl:value-of select="PreviousTotal"/>)
					(change <xsl:value-of select="HitCoveragePoints - PreviousHits"/> / <xsl:value-of select="TotalCoveragePoints - PreviousTotal"/>)
				</xsl:if>
					
			</li>
			<ul>
				<xsl:apply-templates select="Members/*"/>
			</ul>
			<li style="list-style-type:none">}</li>
		</div>
		<br/>	
	</xsl:template>
	
	<xsl:template match="CoverageFile">
		<li>
			<xsl:call-template name="percentage"/>
			<a href="{concat(RelativePath, concat('/', Filename))}"> <xsl:value-of select="Filename" /> </a>
			(<xsl:value-of select="HitCoveragePoints"/>/<xsl:value-of select="TotalCoveragePoints"/>)
			(Was <xsl:value-of select="PreviousHits"/>/<xsl:value-of select="PreviousTotal"/>)	
			<xsl:if test="string-length(MissedLineNumbers) > 0">
				Coverage miss at line# [<xsl:value-of select="MissedLineNumbers"/>]
			</xsl:if>		
		</li>
	</xsl:template>

	
	<xsl:template name="percentage">
		<xsl:variable name="green" select="round(number(HitCoveragePoints) div number(TotalCoveragePoints) * 255)" />
		<xsl:variable name="red" select="255 - round(number(HitCoveragePoints) div number(TotalCoveragePoints) * 255)" />
				
		<font>
			<xsl:attribute name="color">#<xsl:call-template name="color"><xsl:with-param name="baseten" select="$red"/></xsl:call-template><xsl:call-template name="color"><xsl:with-param name="baseten" select="$green"/></xsl:call-template>00</xsl:attribute>
		<xsl:value-of select="format-number(number(HitCoveragePoints) div number(TotalCoveragePoints), '00.##%')"/>	
		</font><xsl:text> </xsl:text>
	</xsl:template>

	<xsl:template name="old-percentage">
		<xsl:choose>
			<xsl:when test="PreviousTotal = 0">non-existant</xsl:when>
			<xsl:otherwise>
			<xsl:variable name="green" select="round(number(PreviousHits) div number(PreviousTotal) * 255)" />
			<xsl:variable name="red" select="255 - round(number(PreviousHits) div number(PreviousTotal) * 255)" />
					
			<font>
				<xsl:attribute name="color">#<xsl:call-template name="color"><xsl:with-param name="baseten" select="$red"/></xsl:call-template><xsl:call-template name="color"><xsl:with-param name="baseten" select="$green"/></xsl:call-template>00</xsl:attribute>
			<xsl:value-of select="format-number(number(PreviousHits) div number(PreviousTotal), '00.##%')"/>	
			</font><xsl:text> </xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="color">
		<xsl:param name="baseten"/>

		<xsl:variable name="high" select="round($baseten div 16)"/>		
		<xsl:variable name="low" select="$baseten mod 16"/><!--high<xsl:value-of select="$high"/>highlow<xsl:value-of select="$low"/>low--><xsl:choose>
			<xsl:when test="$high > 9">
				<xsl:value-of select="translate(substring(string($high),2),'123456','ABCDEF')"/>
			</xsl:when>
			<xsl:otherwise><xsl:value-of select="$high"/></xsl:otherwise>
		</xsl:choose><xsl:choose>
			<xsl:when test="$low > 9">
				<xsl:value-of select="translate(substring(string($low),2),'012345','ABCDEF')"/>
			</xsl:when>
			<xsl:otherwise><xsl:value-of select="$low"/></xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
</xsl:stylesheet>  